<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>1.JS函数-简单计算器功能</title>
    <script>
        // 用户输入任意两个数字的算术运算（简单计算器小功能），并弹出运算后的结果
        num1 = prompt('输入第一个数字');
        symbol = prompt('输入运算符+-*/');
        num2 = prompt('输入第二个数字');
        function getRes(num1, symbol, num2) {
            switch (symbol) {
                case '+':
                    return parseInt(num1) + parseInt(num2);
                    break;
                case '-':
                    return parseInt(num1) - parseInt(num2);
                    break;
                case '*':
                    return parseInt(num1) * parseInt(num2);
                    break;
                case '/':
                    return parseInt(num1) / parseInt(num2);
                    break;
                default:
                    return ('运算符错误');
                    break;
            }
        }
        var re = getRes(num1, symbol, num2);
        alert('运算结果为:' + re);
    </script>
</head>

<body>

</body>

</html>